﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models;

namespace InvExport
{
    public static class AisinoManage
    {
        public static List<KPPathModel> GetKPList()
        {
            try
            {
                var machineList = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\APP Paths\fwkp.exe", true).GetSubKeyNames();
                List<KPPathModel> l = new List<KPPathModel>();
                if(machineList.Length <1)
                    throw new Exception("本机没有安装开票软件！");
                for (int i = 0; i < machineList.Length; i++)
                {
                    KPPathModel k = new KPPathModel();
                    k.Name = machineList[i];
                    var reg =  Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\fwkp.exe\" + k.Name, true);
                    k.DBPath = reg.GetValue("Path") + @"\";
                    k.TaxCode = reg.GetValue("code").ToString();
                    k.MachineNum = reg.GetValue("machine").ToString();
                    l.Add(k);
                }
                return l;
            }
            catch (Exception)
            {
                throw new Exception("未检测到防伪开票系统");
            }
        }
    }
}
